package com.groupseven.happycampus.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.groupseven.happycampus.common.bo.ParttimeDayBo;
import com.groupseven.happycampus.common.bo.ParttimeHourBo;
import com.groupseven.happycampus.common.pojo.ParttimeDay;
import com.groupseven.happycampus.common.pojo.Parttimehour;
import com.groupseven.happycampus.common.vo.LayuiPageVo;
import com.groupseven.happycampus.mapper.ParttimeDayMapper;
import com.groupseven.happycampus.service.ParttimeDayService;
import com.groupseven.happycampus.service.ParttimeHourService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @CreateTime: 2022-07-26  20:38
 */
@Service("/parttimeDayService")
public class ParttimeDayServiceImpl implements ParttimeDayService {

    @Autowired
    private ParttimeDayMapper parttimeDayMapper;

    @Override
    public List<ParttimeDay> parttimeDayList() {
        return parttimeDayMapper.findAllParttimeDays(null);
    }

    @Override
    public LayuiPageVo<ParttimeDay> parttimeDayPageData(Map<String, Object> params) {
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page, limit);

        List<ParttimeDay> parttimedays = parttimeDayMapper.selectParttimeDayByParams(params);

        PageInfo<ParttimeDay> parttimeDayPageInfo = new PageInfo<>(parttimedays);

        LayuiPageVo<ParttimeDay> parttimeDayLayuiPageVo = new LayuiPageVo<>();
        parttimeDayLayuiPageVo.setCode(0);
        parttimeDayLayuiPageVo.setMsg("分页列表数据");
        parttimeDayLayuiPageVo.setCount(parttimeDayPageInfo.getTotal());
        parttimeDayLayuiPageVo.setData(parttimeDayPageInfo.getList());

        return parttimeDayLayuiPageVo;

    }

    @Override
    public int deleteParttimeDay(Integer id) {
        return parttimeDayMapper.deleteParttimeDay(id);
    }

    @Override
    public int deleteParttimeDayByIds(String ids) {
        String[] arrId = ids.split(",");
        return parttimeDayMapper.deleteParttimeDayByIds(arrId);
    }

    @Override
    public int updateParttimeDay(ParttimeDay parttimeDay) {
        return parttimeDayMapper.updateParttimeDay(parttimeDay);
    }

    @Override
    public int insertParttimeDay(ParttimeDay parttimeDay) {
        return parttimeDayMapper.insertParttimeDay(parttimeDay);
    }

    @Override
    public List<ParttimeDayBo> parttimeDayExcelData(ParttimeDay parttimeDay) {

        List<ParttimeDay> parttimedays = parttimeDayMapper.selectParttimeDays(parttimeDay);
        List<ParttimeDayBo> parttimeDayBos = parttimedays.stream().map((p) -> {
            ParttimeDayBo parttimeDayBo = new ParttimeDayBo();
            parttimeDayBo.setId(p.getId());
            parttimeDayBo.setPosition(p.getPosition());
            parttimeDayBo.setWage(p.getWage());
            parttimeDayBo.setCompany(p.getCompany());
            parttimeDayBo.setTelephone(p.getTelephone());
            parttimeDayBo.setRegion(p.getRegion());
            parttimeDayBo.setDeadtime(p.getDeadtime());
            parttimeDayBo.setWorktime(p.getWorktime());
            parttimeDayBo.setDescription(p.getDescription());
            return parttimeDayBo;
        }).collect(Collectors.toList());

        return parttimeDayBos;

    }

}
